home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8085 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: macro that return value, how?
  5. Date: Fri, 01 Mar 1996 15:23:44 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <3136FA60.350B@cmt.lpr.mail.carel.fi>
  8. References: <3133e87b.868433@news.csus.edu>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Jerry Leong wrote:
  16. > Hi,
  17. >     I need to define a macro that will first calculate a given a
  18. > parameter and then return it. How can I do that?
  19. > p/s: Say I pass a value to the macro, macro will perform some
  20. > addition, then return the value.
  21. > #define add1(x)  { x+=VAR; return x; }
  22. > something like that by the above does not compile.
  23. > Thanx in advance!
  24.  
  25. This will compile:
  26.  
  27.     #define    add1(x)    (x += VAR)
  28.  
  29. Remember, the result of an assignment is implicitly returned. So, you can use 
  30. constructs like:
  31.  
  32.     if ((x += 2) == 2)
  33.         DoSomething...
  34.  
  35. and
  36.     if (add1(2) == 2)
  37.         DoSomething...
  38.  
  39. Later,
  40.  AriL
  41. -- 
  42. All my opinions are mine and mine alone.
  43.